package com.apes.autoparts.product.repository;

import com.apes.autoparts.product.model.AccumulatorProduct;
import com.apes.autoparts.product.model.TyreProduct;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 类描述：
 *
 * @ClassName TyreProductRepository
 * @Description 描述
 * @Author lilong
 * @Date 2022/10/26 10:23
 * @Version 1.0
 */
public interface TyreProductRepository extends CustomRepository<TyreProduct, String> {

    @Query(value = "SELECT a.* from auto_tyre_product a , (SELECT max(id) as id from auto_tyre_product \n" +
            "group by brand, specification, figure, load_index, speed_class, anti_explosion) b where a.id = b.id", nativeQuery = true)
    List<TyreProduct> findAllByStandard();

    @Query(value = "select a.id as id from TyreProduct a")
    Set<String> findAllId();

    @Query(value = "select t from TyreProduct t where t.brand = :brand and t.specification = :specification and t.figure = :figure and t.loadIndex = :loadIndex and t.speedClass = :speedClass and t.antiExplosion = :antiExplosion")
    List<TyreProduct> findByBrand(String brand, String specification, String figure, String loadIndex, String speedClass, boolean antiExplosion);

    @Query(value = "select a from TyreProduct a where a.ERPProductId = :productId")
    TyreProduct findOneERPProductId(String productId);

    @Query(value = "SELECT DISTINCT A.SPECIFICATION name FROM AUTO_TYRE_PRODUCT A WHERE REGEXP_LIKE(SPECIFICATION, :specification, 'i')", nativeQuery = true)
    List<Map> findLikeModel(String specification);
}
